<?php

/*
 * File  : modul.php
 * Table : moduls
 */
//session_start();
//cek session

if ((!$_SESSION["USRID"] AND !$_SESSION["USRPASS"]) OR $_SESSION["USRLEVEL"] != "admin") {
    header("location: ../index.php");
    exit();
}
//end
?>

<?php

$aksi = "cms/bab/m_moduls/aksi_modul.php";
switch ($_GET["opr"]) {

    // tampil modul
    default:
        echo "<h2>Modul</h2>";
        echo "<input type=button value='Tambah Modul' onclick=\"window.location.href='?module=modul&opr=tambah';\">";
        echo "<table>";
        echo "<tr><th>No</th><th>Nama Modul</th><th>Link</th><th>Aktif</th><th>Aksi</th></tr>";
        $tampil = mysql_query("SELECT * FROM moduls ORDER BY mod_urutan ASC");
        while ($row = mysql_fetch_array($tampil)) {
            echo "<tr><td>" . $row["mod_urutan"] . "</td>";
            echo "<td>" . $row["mod_nama"] . "</td>";
            echo "<td><a href=" . $row["mod_link"] . ">$" . $row["mod_link"] . "</a></td>";
            echo "<td align=center>" . $row["mod_aktif"] . "</td>";
            echo "<td><a href=?module=modul&opr=edit&id=" . $row["mod_id"] . ">Edit</a> | 
	              <a href=" . URLHOST . "$aksi?module=modul&opr=hapus&id=" . $row["mod_id"] . " onClick=\"return confirm('Hapus Modul " . $row["mod_nama"] . "?')\" >Hapus</a>";
            echo "</td></tr>";
        }
        echo "</table>";
        break;

    // tambah modul
    case "tambah":
        echo "<h2>Tambah Modul</h2>";
        echo "<form method='POST' action='" . URLHOST . "$aksi?module=modul&opr=input'>";
        echo " <table>";
        echo "  <tr><td>Nama Modul</td> <td> : <input type=text name='in_mod_nama'></td></tr>";
        echo "  <tr><td>Link</td>       <td> : <input type=text name='in_mod_link' size=30></td></tr>";
        echo "  <tr><td>Aktif</td>      <td> : <input type=radio name='in_mod_aktif' value='Y' checked>Y 
                                         <input type=radio name='aktif' value='N'>N  </td></tr>";
        echo "  <tr><td colspan=2><input type=submit value=Simpan><input type=button value=Batal onclick=self.history.back()></td></tr>";
        echo " </table></form>";
        break;

    // edit modul
    case "edit":
        $id = $_GET["id"];
        $edit = mysql_query("SELECT * FROM moduls WHERE mod_id='$id'");
        $row = mysql_fetch_array($edit);

        echo "<h2>Edit Modul</h2>";
        echo " <form method='POST' action='" . URLHOST . "$aksi?module=modul&opr=update'>";
        echo "  <input type=hidden name=id value='" . $row["mod_id"] . "'>";
        echo "  <table>";
        echo "   <tr><td>Nama Modul</td><td> : <input type='text' name='in_mod_nama' value='" . $row["mod_nama"] . "'></td></tr>";
        echo "   <tr><td>Link</td><td> : <input type='text' name='in_mod_link' size=30 value='" . $row["mod_link"] . "'></td></tr>";
        if ($row["mod_aktif"] == 'Y') {
            echo "<tr><td>Aktif</td><td> : <input type='radio' name='in_mod_aktif' value='Y' checked>Y<input type='radio' name='in_mod_aktif' value='N'> N</td></tr>";
        } else {
            echo "<tr><td>Aktif</td> <td> : <input type='radio' name='in_mod_aktif' value='Y'>Y<input type='radio' name='in_mod_aktif' value='N' checked>N</td></tr>";
        }
        echo "   <tr><td>Urutan</td><td> : <input type='text' name='in_mod_urutan' size='1' value='" . $row["mod_urutan"] . "'></td></tr>";
        echo "   <tr><td colspan=2><input type=submit value=Update><input type=button value=Batal onclick=self.history.back()></td></tr>";
        echo "  </table>";
        echo " </form>";
        break;
}
?>
